home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / srgp.doc
Encoding:
Text File  |  1993-11-03  |  45.9 KB  |  1,069 lines

  1.                            SRGP for ANSI-C ~~~ (v1.0)
  2.                              David Frederick Sklar
  3.  
  4. The Simple Raster Graphics Package is composed of a library of functions, and a
  5. header file ("srgp.h") that defines custom data types and constants, and 
  6. which prototypes all SRGP routines. This paper is a complete but extremely 
  7. terse description of the ANSI-C SRGP binding --- this is not a tutorial. If you
  8. are new to SRGP, you must read Chapter 2 of Computer Graphics --- Principles 
  9. and Practice (Foley, van Dam, Feiner, and Hughes, Addison-Wesley, 1990).   
  10.  
  11.  
  12.  
  13. 0)    Contrast with Textbook Specification 
  14.  
  15.  
  16.  
  17. 1)    States of the System 
  18.  
  19.  
  20.  
  21. 2)    Canvases 
  22.  
  23.  
  24.  
  25. 3)    Output 
  26.  
  27.        1)   color 
  28.  
  29.        2)   geometric data types 
  30.  
  31.        3)   control of the pattern and font tables 
  32.  
  33.        4)   control of attributes affecting output 
  34.  
  35.        5)   generation of primitives 
  36.  
  37.        6)   generation of primitives 
  38.  
  39.  
  40.  
  41. 4)    The copyPixel Procedure 
  42.  
  43.  
  44.  
  45. 5)    Input 
  46.  
  47.        1)   properties of input devices 
  48.  
  49.        2)   input modes 
  50.  
  51.        3)   input devices 
  52.  
  53.        4)   control of attributes 
  54.  
  55.        5)   control of measures 
  56.  
  57.        6)   sample procedures 
  58.  
  59.        7)   event procedures 
  60.  
  61.  
  62.  
  63. 6)    Inquiry 
  64.  
  65.  
  66.  
  67. 7)    Control of Table Sizes 
  68.  
  69.  
  70.  
  71. 8)    Diagnostics, Debugging, and Optimization 
  72.  
  73.  
  74.  
  75. 9)    Miscellaneous (Hints and Caveats and etc.)  
  76.  
  77.  
  78.  
  79. *************** SECTION 0 >>>> Contrast with Textbook Specification
  80.  
  81. Chapter 3 of the textbook is an academic study of the issues involved in 
  82. implementing any raster graphics package; it is not a description of the actual
  83. internal workings of any particular SRGP implementation. SRGP has been 
  84. implemented on several major types of hardware platforms, and in all cases, 
  85. low-level graphics utilities (QuickDraw on the Mac, X11 on workstations, and 
  86. MetaGraphics on the PC) were used. Because the authors of SRGP were not 
  87. involved in the implementation of the software actually drawing the primitives,
  88. there is no pixel-level compatibility between SRGP applications running on 
  89. different platforms. Fortunately, the inconsistency in appearance will be 
  90. typically noticeable only for extreme values for attributes (very thick 
  91. primitives, rare combinations of write mode and pen/fill style, etc.). 
  92.  
  93. The textbook spec did not discuss how SRGP would work in a windowing 
  94. environment. This document describes how the windowing environment affects 
  95. SRGP, and introduces a few new routines addressing window-specific problems. 
  96.  
  97. The textbook's description of locator echo included "no echo" as an option 
  98. available to the application. However, it was determined that an invisible 
  99. cursor is frustrating to users of a multi-window system. The "no echo" option
  100. is thus honored only by the PC version of SRGP.      
  101.  
  102. The textbook (page 33) claims that the colors black and white are 1 and 0, 
  103. respectively, at all times. This is true for all devices having color tables, 
  104. but it is sometimes false for monochrome systems that are designed for 
  105. white-on-black display. 
  106.  
  107. The textbook did not describe methods for loading bitmap and pixmap patterns 
  108. into the respective pattern tables, for loading fonts into the font table, and 
  109. for loading entries in the color table. See sections 3.1 and 3.3 of this 
  110. document. 
  111.  
  112. There are now "deluxe" versions of the measure records for each input device.
  113. These should be used when timestamps and modifier-key chords are needed. 
  114.  
  115. The textbook specifies the size of the screen canvas cannot be changed by the 
  116. application. That is no longer the case. 
  117.  
  118.  
  119.  
  120. *************** SECTION 1 >>>> States of the System
  121.  
  122. SRGP must be enabled before use, and disabled after use. 
  123.  
  124. void SRGP_begin (char *name, int width, int height, int planes, 
  125.                  boolean enable_trace);
  126.  
  127.     The window which will represent canvas #0 (the SRGP screen-canvas) is 
  128.     created; its initial size is determined by the values of the second and 
  129.     third parameters. The first parameter specifies a name for the application.
  130.     The fifth parameter specifies the initial status of the tracing feature, 
  131.     which is described later in this section. 
  132.  
  133.     The fourth parameter is meaningful only on a display supporting color. It 
  134.     specifies how many planes of the color table should be reserved for SRGP's 
  135.     use; i.e., it places an upper bound on the number of colors that may be 
  136.     displayed simultaneously in the SRGP window. (The upper bound is 2^p 
  137.     colors, where p is the number of planes.) The fourth parameter is ignored 
  138.     when the program is run on a bilevel display. 
  139.  
  140.     If the program is being run on a color display, and you send the special 
  141.     value "0" as the fourth parameter, SRGP will take over the entire color 
  142.     table, giving your application color support as rich as the hardware can 
  143.     offer. (After initializing SRGP, you can inquire the "canvas depth" to 
  144.     determine how many planes are available.) The disadvantage: it will be 
  145.     impossible for the user to simultaneously see the SRGP window's proper 
  146.     coloring and the other clients' windows' proper coloring. Thus, you should 
  147.     request "0" planes only when your application truly needs full control of
  148.     the color table. 
  149.  
  150.     If you request more planes than available, all available planes are 
  151.     allocated, just as if you requested "0" planes. Inquiry is thus your only
  152.     way of determining exactly how many planes are available. 
  153. ------------------------------------------------------------------------------
  154. void SRGP_tracing (boolean);
  155.  
  156.     When tracing is enabled, a message is sent to a logging file (SRGPlogfile 
  157.     in the current directory) each time the application calls an SRGP function;
  158.     the message includes echoing of key parameters. IMPORTANT: Calls to some of
  159.     the input functions are NOT traced; see section 5 for details. See section 
  160.     7 for more information on execution with tracing. 
  161.  
  162.     The initial status of tracing is set when the application calls SRGP_begin,
  163.     but it may be changed at any time via a call to SRGP_tracing. 
  164. ------------------------------------------------------------------------------
  165. void SRGP_allowResize (boolean);
  166.  
  167.     By default, the screen-canvas window cannot be resized by the user. It is 
  168.     advisable that applications live with this restriction. The rare 
  169.     application that needs to allow resizing can use this routine. It is 
  170.     important to note that various artifacts occur when the user actually does 
  171.     take advantage of this freedom and perform a resize: 
  172.  
  173.    1)   The window is cleared to color 0; any information that was on the 
  174.         screen just before the resize is lost. 
  175.  
  176.    2)   The clip rectangle attribute is not changed automatically; the 
  177.         application must be responsible for changing it if necessary. 
  178.  
  179. Obviously, an application that allows resizing must be informed whenever a 
  180. resize occurs, to cope with the aforementioned problems and other 
  181. application-specific ones. SRGP provides a callback utility, which allows an 
  182. application to provide a function to be called whenever a resize has occurred: 
  183. ------------------------------------------------------------------------------
  184. typedef int (*funcptr)();
  185. void SRGP_registerResizeCallback (funcptr);
  186.  
  187.     The application-provided callback function referred to by the 
  188.     function-pointer parameter will be called whenever a resize has occurred. 
  189.     The callback function will receive two integers: the new width and the new 
  190.     height. 
  191. ------------------------------------------------------------------------------
  192. void SRGP_changeScreenCanvasSize (int newwidth, int newheight);
  193.  
  194.     This routine allows the application to modify the size of the screen 
  195.     canvas. As a side-effect, the resize-callback function (if any) is called, 
  196.     just as if the user had requested the resize. 
  197. ------------------------------------------------------------------------------
  198. void SRGP_enableSynchronous (void);
  199.  
  200.     Allows you to enable X's synchronous mode, a useful mode for debugging. The
  201.     mode is discussed rigorously in section 3, and again in section 7. 
  202. ------------------------------------------------------------------------------
  203. void SRGP_end (void);
  204.  
  205.     The screen-canvas window is deleted,  and the logging file is closed.   
  206.  
  207.  
  208.  
  209. *************** SECTION 2 >>>> Canvases
  210.  
  211. SRGP procedures operate on canvases, a canvas being a 2D array of pixels (a 
  212. virtual frame-buffer), whose depth is the number of planes requested by the 
  213. application (via the fourth parameter to SRGP_begin). 
  214.  
  215. Each canvas has its own local coordinate system. The origin (0,0) for the local
  216. coordinate system is the lower-left corner of the canvas, with the X-coordinate
  217. increasing to the right, and the Y-coordinate increasing towards the top. The 
  218. coordinates passed to all primitive-generation procedures are in terms of the 
  219. local coordinate system of the currently-active canvas. 
  220.  
  221. At any given time, one canvas is active: it is the canvas being modified. 
  222. Associated with each canvas is a group of attributes which affect all drawing 
  223. into that canvas. Modification of these attributes is only possible when the 
  224. corresponding canvas is currently active. When a canvas is created, its 
  225. attribute group is initialized to standard default values. 
  226.  
  227. Each canvas is identified by a unique integer canvas index. When SRGP is 
  228. enabled, one canvas already exists and is active: the screen canvas, having 
  229. index 0, whose height and width are determined from the parameters to SRGP_
  230. begin. The screen canvas is the only canvas which is ever visible. No more than
  231. MAX_CANVAS_INDEX+1 canvases (including the screen) may be extant 
  232. simultaneously. 
  233.  
  234. Canvases may be manipulated by the following procedures: 
  235.  
  236. typedef int canvasID;
  237. canvasID SRGP_createCanvas (int width, int height);
  238.  
  239.     An invisible canvas of the specified dimensions is created and its unique 
  240.     index is returned. The new canvas' local-coordinate-system origin (0,0) 
  241.     forms the lower-left corner. (width-1, height-1) forms the upper-right 
  242.     corner. The pixels of a canvas initially store color index 0. Once a canvas
  243.     is created, it can not be resized. (The screen canvas is an exception, but 
  244.     it can only be resized by the user, not by the application.) Upon return, 
  245.     the new canvas (and its corresponding attribute group) are active. If a new
  246.     canvas cannot be created, 0 is returned. 
  247. ------------------------------------------------------------------------------
  248. void SRGP_deleteCanvas (canvasID);
  249.  
  250.     No canvas may be deleted while it is active. Moreover, the screen canvas 
  251.     cannot be deleted with this routine. 
  252. ------------------------------------------------------------------------------
  253. void SRGP_useCanvas (canvasID);
  254.  
  255.     The specified canvas becomes active. Primitives created subsequently are 
  256.     drawn in this canvas, and attributes set subsequently modify this canvas' 
  257.     attribute group.  
  258.  
  259.  
  260.  
  261. *************** SECTION 3 >>>> Output
  262.  
  263.  
  264.  
  265.  
  266. *************** SECTION 3.1 >>>> color
  267.  
  268. SRGP maintains a lookup table (LUT) that maps color indices (which are 
  269. integers, used to index into the LUT) to actual colors. The number of entries 
  270. available in the lookup table is based on the number of planes allocated for 
  271. the application's use (via the fourth parameter to SRGP_begin). The number of 
  272. planes available can be inquired via: 
  273.  
  274. int SRGP_inquireCanvasDepth (void);
  275.  
  276. The legal color indices are numbers between (inclusive) 0 and 2^canvasdepth-1. 
  277. The use of color indices outside that range are clamped to 2^canvasdepth-1. All
  278. implementations support two colors that may be referenced using names instead 
  279. of numbers: SRGP_WHITE and SRGP_BLACK.  
  280.  
  281. On color nodes, SRGP_WHITE is 0 and SRGP_BLACK is 1, and they are the only 
  282. initialized entries in the LUT. One should note, however, that if the first two
  283. entries of the LUT are changed by the application, the names (SRGP_BLACK and 
  284. SRGP_WHITE) are no longer meaningful. 
  285.  
  286. On monochrome displays, the two symbols SRGP_BLACK and SRGP_WHITE are 
  287. implementation-dependent constants. Moreover, the use of a color index greater 
  288. than 1 is clamped to 1 on a monochrome display. 
  289.  
  290. An application may load a contiguous portion of the LUT by creating three 
  291. arrays (one for red, one for blue, one for green) of intensity values, each 
  292. value being an unsigned 16-bit integer. Intensity value 0 represents that 
  293. primary's not contributing at all to the actual color, and 2^16-1 (65,535) 
  294. represents that primary contributing its full glory to the actual color. Note 
  295. that this method for specifying colors is machine-independent; workstations 
  296. supporting only C bits per intensity value will ignore all but the C most 
  297. significant bits of each intensity value. 
  298.  
  299. To load count entries of the LUT, starting with entry start, create the three 
  300. intensity value arrays and then call: 
  301.  
  302. typedef unsigned short ush;
  303. void SRGP_loadColorTable (int start, int count, ush *r, ush *g, ush *b);
  304.  
  305. An easy way to store "common" colors is provided by SRGP. Common colors are 
  306. those colors which have been given names (like "Purple", 
  307. "MediumForestGreen", and "Orange") by the X11 implementation. A complete 
  308. list of the supported colors is usually found in /usr/lib/X11/rgb.txt.  SRGP 
  309. supports only the setting of one LUT entry at a time when using common colors: 
  310.  
  311. void SRGP_loadCommonColor (int entry, char *colorname)
  312.  
  313.  
  314.  
  315. *************** SECTION 3.2 >>>> geometric data types
  316.  
  317. The following SRGP data types allow storage of geometric entities: 
  318.  
  319. typedef struct {
  320.       int x, y;
  321. } point;
  322.  
  323. typedef struct {
  324.       point bottom_left, top_right;
  325. } rectangle;
  326.  
  327. Instances of these data types may be created using these routines: 
  328.  
  329. point SRGP_defPoint (int x, int y);
  330. rectangle SRGP_defRectangle (int left_x, int bottom_y, int right_x, int top_y);
  331.  
  332.     
  333.  
  334.  
  335.  
  336. *************** SECTION 3.3 >>>> control of the pattern and font tables
  337.  
  338. Several of the SRGP attributes are patterns to be used for filling areas and 
  339. for drawing lines and frames. Two pattern tables are supported: one storing 
  340. bitmaps and one storing pixmaps. 
  341.  
  342. The bitmap pattern table is initialized in this way: Pattern 0 is all 
  343. background, and pattern 1 is all foreground. Patterns 1 through 38 are the 
  344. standard Macintosh patterns shown in Volume 1 of Chernicoff's Macintosh 
  345. Revealed, and page I-474 of Inside Macintosh. Patterns 40 through 104 are 
  346. greyscale patterns increasing gradually in intensity from all background (40) 
  347. to all foreground (104). All other entries in the bitmap pattern table are 
  348. undefined; use of an undefined pattern is a fatal error.  To see an array of 
  349. tiles showing the default bitmap pattern table, run the example program show_
  350. patterns. 
  351.  
  352. Only entry 0 in the pixmap pattern table is defined, and it is simply an 
  353. all-color-0 pattern. 
  354.  
  355. SRGP provides two methods for changing entries in the pattern table: 
  356.  
  357. **  You can have SRGP load one or more patterns from a file which stores 
  358.     ASCII-text pattern specifications you can create using a text editor or 
  359.     convenient bitmap-editor programs (if available). 
  360.  
  361. **  You can give SRGP a pattern specification in the form of an array of 
  362.     numbers. 
  363.  
  364. To load a bitmap pattern from a file, open the file and pass the stream to the 
  365. function: 
  366.  
  367. int SRGP_loadBitmapPatternsFromFile (FILE *stream);
  368.  
  369. The input may be composed of one or more pattern specifications ("specs"). 
  370. Each spec must occupy exactly two lines and must match this format: 
  371.  
  372. static char bitpat_Xy[] = {
  373.    0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??};
  374.  
  375. where X is a non-negative integer specifying the index of the entry to be set, 
  376. y is any arbitrary garbage between the integer and the left square-brace, and 
  377. 0x?? is any arbitrary byte value represented in hexadecimal. This specification
  378. format is created automatically by X's bitmap editor bitmap. 
  379.  
  380. As a convenience, any lines beginning with # are ignored, but these comment 
  381. lines must not interrupt a single two-line spec sequence. Blank unused lines 
  382. are not allowed anywhere in the file. 
  383.  
  384. The closing of the input stream must be performed by the caller. This function 
  385. returns 1 if any problems at all occurred; since its parser makes no attempt at
  386. error recovery, it is wise to check the return value. 
  387.  
  388. To load a pixmap pattern from a file, use this routine whose functionality is 
  389. similar to that of the one for bitmap patterns: 
  390.  
  391. int SRGP_loadPixmapPatternsFromFile (FILE *stream);
  392.  
  393. The input may be composed of one or more pattern specifications, each matching 
  394. this format: 
  395.  
  396. static int pixpat_Xy[] = {
  397.    ?, ?, ?, ?, ?, ?, ?, ?,
  398.    ?, ?, ?, ?, ?, ?, ?, ?,
  399.    ?, ?, ?, ?, ?, ?, ?, ?,
  400.    ?, ?, ?, ?, ?, ?, ?, ?,
  401.    ?, ?, ?, ?, ?, ?, ?, ?,
  402.    ?, ?, ?, ?, ?, ?, ?, ?,
  403.    ?, ?, ?, ?, ?, ?, ?, ?,
  404.    ?, ?, ?, ?, ?, ?, ?, ?};
  405.  
  406. In this specification, each ? represents a decimal integer color index. 
  407.  
  408. Applications generating the patterns at runtime can use these routines to set 
  409. one entry at a time: 
  410.  
  411. void SRGP_loadBitmapPattern (int pattern_id, char *data);
  412. void SRGP_loadPixmapPattern (int pattern_id, int *data);
  413.  
  414.     The former routine expects an array of 8 characters; the latter an array of
  415.     64 integers.  
  416.  
  417. Another attribute is the font to be used for text. SRGP provides a table of 
  418. fonts that may be used and modified by the application. Each entry is 
  419. identified by a unique font index (ranging from 0 to MAX_FONT_INDEX). 
  420. Initially, only entry #0 of the font table is defined. The application can 
  421. modify the table via: 
  422.  
  423. void SRGP_loadFont (int fontindex, char *name);
  424.  
  425.     This function allows the application to load a font into a given entry of 
  426.     the table. The name of the font is simply the name of a file containing the
  427.     font's description. The filename must be absolute (begin with a slash) 
  428.     unless the font lies in the default directory that is used by X in font 
  429.     searches.  
  430.  
  431.  
  432.  
  433. *************** SECTION 3.4 >>>> control of attributes affecting output
  434.  
  435. These procedures allow control of the value of each attribute associated with 
  436. the currently-active canvas. 
  437.  
  438. typedef enum {WRITE_REPLACE, WRITE_XOR, WRITE_OR, WRITE_AND} writeModeType;
  439. void SRGP_setWriteMode (writeModeType);
  440.  
  441.     The write mode affects the writing of a pixel, the generation of a 
  442.     primitive, and the copying of a rectangular portion of a canvas. The 
  443.     default is WRITE_REPLACE.  
  444. ------------------------------------------------------------------------------
  445. void SRGP_setClipRectangle (rectangle);
  446.  
  447.     All subsequently-created primitives and subsequent pixel-copyings are 
  448.     clipped to the specified rectangle. The default clipping rectangle is 
  449.     exactly the size of the associated canvas. It is illegal to set the 
  450.     clipping rectangle to a rectangle which does not lie completely within the 
  451.     boundaries of its associated canvas. 
  452. ------------------------------------------------------------------------------
  453. void SRGP_setFont (int font_index);
  454.  
  455.     The application chooses from a font by giving the index (ranging from 0 to 
  456.     MAX_FONT_INDEX) into the font table. The default is 0, the only entry in 
  457.     the font table which is initialized when SRGP is launched. 
  458. ------------------------------------------------------------------------------
  459. void SRGP_setMarkerSize (int width_in_pixels);
  460.  
  461.     This describes the dimensions of the imaginary square that circumscribes a 
  462.     marker's image. 
  463. ------------------------------------------------------------------------------
  464. typedef enum {MARKER_CIRCLE, MARKER_SQUARE, MARKER_X} markerStyleType;
  465. void SRGP_setMarkerStyle (markerStyleType);
  466.  
  467.     SRGP supports three different marker shapes, circle being the default. 
  468. ------------------------------------------------------------------------------
  469. typedef enum {CONTINUOUS, DASHED, DOTTED, DOT_DASHED} lineStyleType;
  470. void SRGP_setLineStyle (lineStyleType);
  471. void SRGP_setLineWidth (int width_in_pixels);
  472.  
  473.     The default line style is continuous, default line width is 1.   
  474. ------------------------------------------------------------------------------
  475. void SRGP_setColor (int color_index);
  476.  
  477.     This sets the foreground (drawing) color to the color that is stored at the
  478.     given entry in the LUT; the default is 1. 
  479. ------------------------------------------------------------------------------
  480. void SRGP_setBackgroundColor (int color_index);
  481.  
  482.     Default is 0. The background color is used to color the pixels denoted by 0
  483.     values in opaque bitmap pattern fills. 
  484. ------------------------------------------------------------------------------
  485. void SRGP_setPlaneMask (int bitmask);
  486.  
  487.     The default plane mask is all 1's. The lowest p bits of the integer bitmask
  488.     are used, where p is the number of planes allocated for the application. 
  489.     (Warning: Currently the Macintosh version does not support this!)  
  490. ------------------------------------------------------------------------------
  491. typedef enum {
  492.   SOLID, BITMAP_PATTERN_OPAQUE, BITMAP_PATTERN_TRANSPARENT, PIXMAP_PATTERN}
  493.     drawStyle;
  494. void SRGP_setFillStyle (drawStyle);
  495. void SRGP_setPenStyle (drawStyle);
  496.  
  497.     Fill style affects filled primitives; pen style affects outlined (framed) 
  498.     primitives or lines. Text is not affected by either of these attributes. 
  499.     Default is SOLID.  
  500. ------------------------------------------------------------------------------
  501. void SRGP_setFillBitmapPattern (int pattern_index);
  502. void SRGP_setFillPixmapPattern (int pattern_index);
  503. void SRGP_setPenBitmapPattern (int pattern_index);
  504. void SRGP_setPenPixmapPattern (int pattern_index);
  505.  
  506.     Denotes the entry in the appropriate pattern table which is to be used when
  507.     the fill or pen style is not SOLID.  
  508.  
  509. The entire set of attributes may be set to a previously-stored group of values 
  510. using the function described next. Later in this reference is described the 
  511. function (SRGP_inquireAttributes) that allows inquiry of the current attribute 
  512. group. 
  513.  
  514. typedef struct ... attribute_group;   /* see srgppublic.h for details */
  515. void SRGP_setAttributes (attribute_group);
  516.  
  517.     The parameter's value should have been obtained from a previous call to 
  518.     SRGP_inquireAttributes. 
  519.  
  520.  
  521.  
  522. *************** SECTION 3.5 >>>> generation of primitives
  523.  
  524. The functions described in this section perform drawing in the currently active
  525. canvas. For each primitive generator described, the list of attributes 
  526. affecting its operation is presented. 
  527.  
  528. An ellipse is specified in terms of the rectangle within which it is inscribed.
  529. Polygons, rectangles, and ellipses may be generated as framed or filled. A 
  530. filled primitive is all-interior --- the frame is not displayed. 
  531.  
  532. WARNING: because SRGP by default uses X's asynchronous mode, a call to an 
  533. output primitive routine may not produce an image for an arbitrary length of 
  534. time, or may not produce an image at all! This is because in asynchronous mode,
  535. X commands are buffered, being actually sent only when/if the buffer gets full 
  536. or when/if your program attempts to perform any kind of graphical input. If 
  537. your program often uses SRGP input devices, this should not be a problem; but, 
  538. if your application is output-only or has sleeps or long pauses not related to 
  539. waiting for input, you must explicitly flush the X buffer at appropriate times,
  540. using this function: 
  541.  
  542. void SRGP_refresh (void);
  543.  
  544. Alternatively, you can place X in synchronous mode using the routine described 
  545. in section 1. This guarantees a buffer flush after each application-level call 
  546. to SRGP output routines, but at great performance cost. 
  547.  
  548. void SRGP_point (point);
  549. void SRGP_pointCoord (int x, int y);
  550.  
  551.     Current write mode, foreground color, and plane mask apply. 
  552. ------------------------------------------------------------------------------
  553. void SRGP_marker (point)
  554. void SRGP_markerCoord (int x, int y)
  555.  
  556.     Current marker style, marker size, write mode, foreground color, and plane 
  557.     mask apply. 
  558. ------------------------------------------------------------------------------
  559. void SRGP_line (point pt1, point pt2);
  560. void SRGP_lineCoord (int x1, int y1,  int x2, int y2);
  561.  
  562. void SRGP_rectangle (rectangle);
  563. void SRGP_rectanglePt (point lower_left, point upper_right);
  564. void SRGP_rectangleCoord (int left_x, int lower_y,  int right_x, int upper_y);
  565.  
  566.     Current write mode, plane mask, colors, line width, line style, and pen 
  567.     style apply. 
  568. ------------------------------------------------------------------------------
  569. void SRGP_polyPoint (int vert_count, point *vertices);
  570. void SRGP_polyMarker (int vert_count, point *vertices);
  571. void SRGP_polyLine (int vert_count, point *vertices);
  572. void SRGP_polygon (int vert_count, point *vertices);
  573.  
  574. void SRGP_polyPointCoord (int vert_count, int *x_coords, int *y_coords);
  575. void SRGP_polyMarkerCoord (int vert_count, int *x_coords, int *y_coords);
  576. void SRGP_polyLineCoord (int vert_count, int *x_coords, int *y_coords);
  577. void SRGP_polygonCoord (int vert_count, int *x_coords, int *y_coords);
  578.  
  579.     Current write mode, plane mask, colors, line width, line style, and pen 
  580.     style apply. SRGP_polygon(Coord) automatically connects the first and last 
  581.     vertices to form a closed polygon. Lists of vertices and coordinates are 
  582.     limited in size to MAX_POINTLIST_SIZE. 
  583. ------------------------------------------------------------------------------
  584. void SRGP_ellipse (rectangle bounds);
  585. void SRGP_ellipseArc (rectangle bounds, double startangle, double endangle);
  586.  
  587.     Current write mode, plane mask, colors, line width, line style, and pen 
  588.     style apply. An arc extends counterclockwise from the start angle to the 
  589.     end angle. Angles are in rectangular degrees and must lie between 0 and 
  590.     360, with 0 degrees being a horizontal ray extending towards positive 
  591.     infinity. 
  592. ------------------------------------------------------------------------------
  593. void SRGP_fillPolygon (int vert_count, point *vertices);
  594. void SRGP_fillPolygonCoord (int vert_count, int *x_coords, int *y_coords);
  595. void SRGP_fillEllipse (rectangle);
  596. void SRGP_fillEllipseArc (rectangle bounds, double startangle, double endangle);
  597. void SRGP_fillRectangle (rectangle);
  598. void SRGP_fillRectanglePt (point lower_left, point upper_right);
  599. void SRGP_fillRectangleCoord (int left_x, int lower_y, int right_x, int upper_y);
  600.  
  601.     Current write mode, plane mask, colors, and fill style apply. 
  602. ------------------------------------------------------------------------------
  603. void SRGP_text (point origin, char *str);
  604.  
  605.     Current write mode, plane mask, foreground color, and font apply. The 
  606.     origin marks the leftmost point to be affected by the text, and marks the 
  607.     horizontal baseline for the text, under which only the text's characters' 
  608.     descenders will appear. 
  609.  
  610.  
  611.  
  612. *************** SECTION 3.6 >>>> audio output
  613.  
  614.  
  615. void SRGP_beep (void);
  616.  
  617.     
  618.  
  619.  
  620.  
  621. *************** SECTION 4 >>>> The copyPixel Procedure
  622.  
  623. This procedure allows a portion of a canvas to be copied into another part of 
  624. itself or into another canvas. See the textbook for more information on this 
  625. powerful feature. 
  626.  
  627. void SRGP_copyPixel (canvasID source_canvas, rectangle source_rect, 
  628.                      point dest_corner);
  629.  
  630.     The copying operation is composed of two parts. First, a copy of a 
  631.     rectangular portion of a canvas is created. Then, the copy is placed 
  632.     somewhere within the currently-active canvas. (The currently-active canvas 
  633.     may or may not also be the canvas providing the source of the copy.) 
  634.  
  635.     dest_corner describes the lower-left corner of the destination rectangle 
  636.     (lying inside the currently-active canvas) having the same size as source_
  637.     rect. 
  638.  
  639.     Only the rectangular portion of source_rect which lies within the 
  640.     boundaries of the source canvas is copied. The placement operation is 
  641.     affected by the current clipping-rectangle and write-mode.  
  642.  
  643.  
  644.  
  645. *************** SECTION 5 >>>> Input
  646.  
  647. An application program obtains input from an operator by controlling a set of 
  648. logical input devices, each representing a unique input technique. Each device 
  649. may be placed in a number of different input modes, each representing a unique 
  650. type of interaction with the input device. 
  651.  
  652.  
  653.  
  654. *************** SECTION 5.1 >>>> properties of input devices
  655.  
  656. Each input device is described in terms of these information: a measure, a 
  657. trigger set, and a set of attributes. 
  658.  
  659. The measure of an input device is the value currently associated with the 
  660. device. 
  661.  
  662. The trigger of an an input device is the action which indicates a significant 
  663. moment associated with the device. 
  664.  
  665. The attributes of an input device are the parameters of the device which are 
  666. under application-control, primarily the echo characteristics. 
  667.  
  668. At any given time, each device is either active or inactive. The process of 
  669. activation places a device into an active state; the process of deactivation 
  670. places it into an inactive state. Zero or more devices may be simultaneously 
  671. active. 
  672.  
  673.  
  674.  
  675. *************** SECTION 5.2 >>>> input modes
  676.  
  677. There are three modes in which input devices operate. (Initially, each device 
  678. is inactive.) The modes' names are listed below, accompanied by a description: 
  679.  
  680.          INACTIVE   When device X is inactive, no events are posted concerning 
  681.                     it, and its measure is not available to the application. 
  682.  
  683.            SAMPLE   When device X is in Sample mode, it is active. The 
  684.                     application may call SRGP_sampleX to immediately obtain the
  685.                     measure of input device X. The firings of X-triggers do not
  686.                     have any effects. 
  687.  
  688.             EVENT   When device X is in Event mode, it is active. The firing of
  689.                     an X-trigger causes an input report (containing the measure
  690.                     of the device at the time of the firing) to be appended to 
  691.                     the input queue. 
  692.  
  693. The following function allows control of the input modes and echoing for all 
  694. input devices: 
  695.  
  696. typedef enum {NO_DEVICE, LOCATOR, KEYBOARD} inputDevice;
  697. typedef enum {INACTIVE, SAMPLE, EVENT} inputMode;
  698. void SRGP_setInputMode (inputDevice, inputMode);
  699.  
  700.     The specified input device is placed in the specified mode. Whenever device
  701.     X's mode is changed from Inactive to either Sample or Event, the device is 
  702.     activated: its measure is initialized (to a static default initial value, 
  703.     or to a value specified by the application while the device was inactive) 
  704.     and echoing begins. When X's mode is set to Event, queueing of the device's
  705.     event reports is enabled as well. When X's mode is changed from Event, all 
  706.     queued events for that device are discarded. 
  707.  
  708.     When X's mode is set to Inactive, the device is deactivated: trigger 
  709.     firings from the device are ignored and echoing is disabled. 
  710.  
  711.  
  712.  
  713. *************** SECTION 5.3 >>>> input devices
  714.  
  715. The SRGP input devices are described in this section. 
  716.  
  717.  
  718.  
  719.   LOCATOR   The measure of the Locator device incorporates a position expressed
  720.             in the coordinate system of the screen canvas, a chord giving the 
  721.             status of the mouse buttons, and the number of the button which 
  722.             most recently experienced a transition. The button-chord array is 
  723.             indexed using three constants: LEFT_BUTTON, MIDDLE_BUTTON, and 
  724.             RIGHT_BUTTON.  
  725.  
  726.             The button-mask attribute of this device determines which of the 
  727.             buttons are of interest when the device is active in Event mode: 
  728.             only buttons specified in this mask can trigger an event. 
  729.  
  730.                typedef enum {UP, DOWN} buttonStatus;
  731.                typedef struct {
  732.                   point position;
  733.                   buttonStatus button_chord[3];
  734.                   int button_of_last_transition;
  735.                } locator_measure;
  736.  
  737.             The "deluxe" version of the locator measure includes a chord 
  738.             giving the status of three primary modifier keys at the time of the
  739.             last button transition, and a timestamp structure. The modifier 
  740.             chord array is indexed via SHIFT, CONTROL, and META. (Warning: the 
  741.             physical key to which the META modifier maps varies from system to 
  742.             system; moreover, some window manager setups will swallow button 
  743.             presses modified by these keys, and thus applications that rely on 
  744.             modifier keys lose some portability.)  The timestamp specifies the 
  745.             time at which the most recent change to the measure occurred --- 
  746.             i.e., successive sampling of a non-moving locator produces a 
  747.             "constant" timestamp. 
  748.  
  749.               typedef struct {
  750.                  int seconds;  /* duration since application launch */
  751.                  int ticks;    /* a tick is 1/60th second */
  752.               } srgp_timestamp;
  753.  
  754.               typedef struct {
  755.                  point position;
  756.                  buttonStatus button_chord[3];
  757.                  int button_of_last_transition;
  758.                  buttonStatus modifier_chord[3]; /* status at last transition */
  759.                  srgp_timestamp timestamp;
  760.               } deluxe_locator_measure;
  761.  
  762.  
  763.  
  764.  KEYBOARD   The measure of this device is a character string, storing either a 
  765.             single ASCII character code or a sequence of printable characters. 
  766.  
  767.             The "deluxe" version of the measure includes the modifier chord,
  768.             a timestamp, and a position:
  769.  
  770.                typedef struct {
  771.                   char *buffer;   /* ptr to space allocated by application */
  772.                   int buffer_length;   /* set by application */
  773.                   buttonStatus modifier_chord[3];
  774.                   point position;
  775.                   srgp_timestamp timestamp;
  776.                } deluxe_keyboard_measure;
  777.  
  778.             The processing-mode attribute of this device determines which of 
  779.             the two meanings is given to the measure of the device: 
  780.  
  781.              RAW:   When a key is hit, the measure stores a string of length 1 
  782.                     whose single element is the ASCII character code of the key
  783.                     hit (taking into account the status of the shift and 
  784.                     control modifier keys) and a trigger-firing occurs. The 
  785.                     modifier chord shows the status of the modifiers when the 
  786.                     key was hit. No echo occurs in RAW mode. 
  787.  
  788.             EDIT:   (the default) When a key representing a printable character
  789.                     is hit and the string is not yet full, the character is 
  790.                     appended to the string. When the backspace key is hit, the 
  791.                     last character of the string is deleted. When return is 
  792.                     hit, an event is sent (representing the full value of the 
  793.                     string) and the measure is set to the null string. In EDIT 
  794.                     mode, the modifier chord is not maintained and should be 
  795.                     ignored. 
  796.  
  797. C programmers should take care to allocate a buffer large enough to include the
  798. null character that terminates the string measure. For example, two bytes are 
  799. needed to store a RAW-mode measure. 
  800.  
  801.  
  802.  
  803. *************** SECTION 5.4 >>>> control of attributes
  804.  
  805. The following procedures set the attributes for input devices. Attributes may 
  806. be set at any time, regardless of whether the device is active or inactive. 
  807.  
  808. void SRGP_setLocatorButtonMask (int value);
  809.  
  810.     The value should be 0 or an OR combination of one or more of the following 
  811.     defined constants: LEFT_BUTTON_MASK, MIDDLE_BUTTON_MASK, and RIGHT_BUTTON_
  812.     MASK. Initially the value is LEFT_BUTTON_MASK: meaning only the left button
  813.     (which is the only button on a 1-button mouse) generates events. 
  814. ------------------------------------------------------------------------------
  815. SRGP_setLocatorEchoType (int value);  /* CURSOR, RUBBER_LINE, or RUBBER_RECT */
  816.  
  817.     An application can choose to have just the cursor, or to also have a 
  818.     rubber-primitive (anchored at a fixed point with the other end of the 
  819.     primitive following the cursor's movement). Note: the value NO_ECHO is also
  820.     accepted, but it is ignored on all platforms except the IBM PC. 
  821.  
  822. SRGP provides a cursor table whose 0th entry is initialized to an arrow; all 
  823. other entries are unusable until loaded. 
  824.  
  825. void SRGP_loadCursorTable (int cursor_index, int shape);
  826. /* shape: any constant defined in <X11/cursorfont.h> */
  827.  
  828.     Legal cursor indices are numbers between 0 and MAX_CURSOR_INDEX, inclusive.
  829.     The shape may be any constant defined in the "cursorfont.h" file that is 
  830.     provided by X11.  
  831.  
  832. The attributes for the locator's echo are set via: 
  833.  
  834. void SRGP_setLocatorEchoCursorShape (int cursor_index);
  835. void SRGP_setLocatorEchoRubberAnchor (point position);
  836.  
  837.     
  838.  
  839. The keyboard's attributes are set via: 
  840.  
  841. typedef enum {EDIT, RAW} keyboardMode;
  842. void SRGP_setKeyboardProcessingMode (keyboardMode);
  843. void SRGP_setKeyboardEchoColor (int color_index);
  844. void SRGP_setKeyboardEchoFont (int font_index);
  845. void SRGP_setKeyboardEchoOrigin (point position);
  846.  
  847.     Keyboard echo attributes are only meaningful when the keyboard is active in
  848.     EDIT processing mode. Setting the keyboard's processing mode (default EDIT)
  849.     clears the keyboard's measure as a side-effect. 
  850.  
  851.  
  852.  
  853. *************** SECTION 5.5 >>>> control of measures
  854.  
  855. The measure of a device may be changed by the application at any time. If the 
  856. change is performed while the device is active, the measure immediately 
  857. changes, as does as echoing concerning the device. If it is done while the 
  858. device is inactive, the specified measure is used to initialize the device's 
  859. measure the next time it is activated. NOTE: the button-related fields of the 
  860. locator measure may not be changed by the application. 
  861.  
  862. void SRGP_setLocatorMeasure (point value);
  863. void SRGP_setKeyboardMeasure (char *value);
  864.  
  865.     
  866.  
  867.  
  868.  
  869. *************** SECTION 5.6 >>>> sample procedures
  870.  
  871. The involved input device must be in SAMPLE mode. Each function places in the 
  872. provided place the current measure of the corresponding device. Calls to these 
  873. routines are NOT traced. 
  874.  
  875. The SRGP_sampleKeyboard function copies the keyboard measure into the given 
  876. character-array buffer of size buffer_length. If the current keyboard measure 
  877. is longer than (bufferlength-1) bytes, it is truncated. Similarly, the 
  878. keyboard-measure structure sent to SRGP_sampleDeluxeKeyboard must have pre-set 
  879. values for its buffer and buffer_length fields. 
  880.  
  881. void SRGP_sampleLocator (locator_measure *measure);
  882. void SRGP_sampleKeyboard (char *buffer, int buffer_length);
  883. void SRGP_sampleDeluxeLocator (deluxe_locator_measure *measure);
  884. void SRGP_sampleDeluxeKeyboard (deluxe_keyboard_measure *measure);
  885.  
  886.     
  887.  
  888.  
  889.  
  890. *************** SECTION 5.7 >>>> event procedures
  891.  
  892. Calls to these functions are NOT traced. 
  893.  
  894. inputDevice SRGP_waitEvent (int maximum_wait_time);
  895.  
  896.     If, upon entry, the event queue is not empty, the procedure exits 
  897.     immediately, identifying the event report at the head of the queue and 
  898.     removing the report from the queue. Otherwise, the application enters a 
  899.     wait state, which is exited upon the first occurrence of a trigger-firing 
  900.     from any device which is currently in EVENT mode. The wait state never 
  901.     lasts for more than the number of ticks (1/60 seconds) given in the maximum
  902.     _wait_time parameter (which, when negative, represents infinity). An 
  903.     application can "poll" the queue (avoiding a wait state) by specifying 
  904.     "0" as the maximum wait time. 
  905.  
  906.     The return value identifies the device causing the event. The special value
  907.     NO_DEVICE is returned when the procedure exits due to timeout. 
  908.  
  909. When an application discovers that an input event (not a timeout) caused the 
  910. return of SRGP_waitEvent, it may obtain the data associated with the involved 
  911. event by using the appropriate "get" function, whose parameters and return 
  912. values mimic those of the sample functions: 
  913.  
  914. void SRGP_getLocator (locator_measure *measure);
  915. void SRGP_getKeyboard (char *measure, int buffer_length);
  916. void SRGP_getDeluxeLocator (deluxe_locator_measure *measure);
  917. void SRGP_getDeluxeKeyboard (deluxe_keyboard_measure *measure);
  918.  
  919.     
  920.  
  921.  
  922.  
  923. *************** SECTION 6 >>>> Inquiry
  924.  
  925. NOTE: Calls to these routines are NOT traced. 
  926.  
  927. void SRGP_inquireAttributes (attribute_group *group);
  928.  
  929.     The current states of all attributes are copied into the provided group 
  930.     structure. For information on the names of the fields in the structure, see
  931.     srgppublic.h. 
  932. ------------------------------------------------------------------------------
  933. canvasID SRGP_inquireActiveCanvas (void);
  934.  
  935.     This function allows inquiry of the ID of the currently-active canvas. 
  936. ------------------------------------------------------------------------------
  937. rectangle SRGP_inquireCanvasExtent (canvasID);
  938. void SRGP_inquireCanvasSize (canvasID, int *width, int *height);
  939.  
  940.     Two functions allowing inquiry of the size of a canvas. 
  941. ------------------------------------------------------------------------------
  942. int SRGP_inquireCanvasDepth (void);
  943.  
  944.     Returns the number of planes available in all canvases. 
  945. ------------------------------------------------------------------------------
  946. void SRGP_inquireTextExtent (char *str, int *width, int *ascent, int *descent);
  947.  
  948.     This procedure allows inquiry of the rectangular extent which would be 
  949.     covered by the output of the given character string with the current font 
  950.     attribute.  
  951.  
  952.  
  953.  
  954. *************** SECTION 7 >>>> Control of Table Sizes
  955.  
  956. The tables that store patterns, fonts, etc. have default sizes that in many 
  957. cases are acceptable. You may, however, choose to reduce the size of a table to
  958. save memory (if you're working on a Mac Plus, for instance) or increase the 
  959. size of a table if you need more entries. You may change the size of a table 
  960. only before SRGP is initialized! 
  961.  
  962. void SRGP_setMaxCanvasIndex (int i);
  963. void SRGP_setMaxPatternIndex (int i);
  964. void SRGP_setMaxCursorIndex (int i);
  965. void SRGP_setMaxFontIndex (int i);
  966. void SRGP_setMaxPointlistSize (int i);
  967.  
  968.     See srgp_sphigs.h for the defaults for these sizes. NOTE: Do not reduce the
  969.     size of the pattern table!  
  970.  
  971.  
  972.  
  973. *************** SECTION 8 >>>> Diagnostics, Debugging, and Optimization
  974.  
  975. SRGP offers two features that aid the developer in debugging an application. 
  976. Both of these features may be disabled or enabled by the programmer and even by
  977. the user at run-time, in order to optimize the execution. 
  978.  
  979. The first feature is tracing. When enabled, each call to an SRGP routine 
  980. (except a few input-related routines) produces a detailed message in a log 
  981. file. A parameter to SRGP_begin() controls the initial state of tracing; calls 
  982. to SRGP_tracing can be used to control the state during runtime. Early test 
  983. runs of an application should always be performed with tracing enabled. For 
  984. more details on tracing, see Section 1. 
  985.  
  986. The second feature is parameter verification. All SRGP routines perform 
  987. verification of all parameters (except those that are pointers to an array or 
  988. structure) before they commence operation. All errors are fatal and produce a 
  989. crash with a detailed error message. Only when a program is fully debugged 
  990. should optimization efforts include disabling parameter verfication! You may 
  991. permanently disable verification and tracing via: 
  992.  
  993. void SRGP_disableDebugAids (void);
  994.  
  995. If your application crashes due to an X server error or in the scope of an SRGP
  996. routine, there are two possibilities (assuming the X server is not at fault): 
  997.  
  998. **  You passed invalid data to an SRGP routine, via a parameter that is not 
  999.     subject to SRGP's verification. For example, SRGP assumes the sanity of 
  1000.     pointers it receives (e.g., pointer to a vertex list). 
  1001.  
  1002. **  There is a bug in SRGP. To help the system administrator locate or report 
  1003.     the bug, edit the application to use the following sequence to initialize, 
  1004.     and run the program with tracing and parameter verification enabled: 
  1005.  
  1006.        SRGP_beginWithDebug (name, w, h, p, TRUE);
  1007.        SRGP_enableSynchronous();
  1008.  
  1009. About SRGP's diagnostics: There are two types of run-time errors. The first 
  1010. type is parameter-verification errors; the verification can be turned off as 
  1011. mentioned earlier. The second type occurs when a problem unrelated to bad input
  1012. occurs, like running out of memory when attempting to allocate a canvas. All 
  1013. errors -- of both types -- are considered fatal by default, and cause a crash 
  1014. after displaying an informative message to the user. Some programmers might 
  1015. wish to make all errors be non-fatal, so program execution can continue (with 
  1016. suitable recovery algorithms, of course). The following routine can be used to 
  1017. choose between fatal and non-fatal error handling: 
  1018.  
  1019. typedef enum {FATAL_ERRORS, NON_FATAL_ERRORS} errorHandlingMode;
  1020. void SRGP_setErrorHandlingMode (errorHandlingMode);
  1021.  
  1022. When an error is detected by SRGP while the mode is NON_FATAL_ERRORS, no 
  1023. message is issued to the user; rather, a global variable is set to a positive 
  1024. integer that represents the error: 
  1025.  
  1026. #include "srgp_errtypes.h"
  1027. extern int SRGP_errorOccurred;
  1028.  
  1029. The header file contains symbolic constants mapping the integers to error 
  1030. types. The global variable is never reset to 0 by SRGP; the application is 
  1031. responsible for examining and resetting it. Obviously, non-fatal mode should be
  1032. used with great care, and only late in an application's development.  
  1033.  
  1034.  
  1035.  
  1036. *************** SECTION 9 >>>> Miscellaneous (Hints, Caveats, etc.)
  1037.  
  1038. An SRGP application cannot control multiple windows: only canvas #0 is 
  1039. represented by a visible window.   
  1040.  
  1041. Keep the difference between synchronous and asynchronous modes in mind: if a 
  1042. brief application produces no output, it may be because the X command buffer is
  1043. not being flushed. For more information, see section 3.4. 
  1044.  
  1045. On color machines, if the SRGP application requests full color support (by 
  1046. passing 0 as the fourth parameter to SRGP_begin), the windows of clients other 
  1047. than the SRGP application will not show their "true" colors whenever the 
  1048. cursor lies within the SRGP window; likewise, the SRGP window will show false 
  1049. colors whenever the cursor lies outside its extent. This can be disconcerting, 
  1050. and an application that does not need full use of the color table should 
  1051. instead reserve a subpart of the color table by sending a positive integer to 
  1052. SRGP_begin. (Note: if your application does not call SRGP_waitEvent often 
  1053. enough, SRGP will not be notified of the cursor's location, and thus it may not
  1054. be able to restore true colors when the cursor enters the SRGP window.) 
  1055.  
  1056. Note that color indices are integers (rather than unsigned longs, as in X). 
  1057. This means that in the rare event that one is using a machine with a 32-bit 
  1058. deep framebuffer but with only 16-bit integers, the full set of LUT entries 
  1059. will not be available.  
  1060.  
  1061. Most machines support X's backing-store feature; on these machines, SRGP 
  1062. refreshes its window whenever any part that was previously covered is 
  1063. re-exposed, or whenever it is de-iconized. On other machines, the graphic 
  1064. information in the window is volatile and is lost whenever it is covered or 
  1065. iconized. 
  1066.  
  1067.  
  1068.                                   --- FIN ---
  1069.